<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class eng_diagnosis_model extends CI_Model
{
	
	public function __construct()
	{
		parent::__construct();

	}
public function get_view($id)
	{
	$this->datatables
			->select("customer.id as id,case.case_no,diagnosis.date,status.name,customer.customer_name,customer.mobile")
			->from('diagnosis','customer','users','status','case')
			->join('customer','customer.service_id=diagnosis.service_id')
			->join('users','users.id=diagnosis.enginer_id')
			->join('case','case.service_id=customer.service_id')
			->join('status','diagnosis.status_id=status.id')
			->where('users.id',$id)
			->where('diagnosis.status_id',1)
		    ->add_column("Actions",
			"<center>		
								<a href='index.php/engineer/diagnosis/view_detail/$1'>
								<i class='icon-edit 'title='View Detail'></i>
								</a>
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}
	public function nonwarranty_view($id)
	{
	$this->datatables
			->select("customer.id as id, nonwarranty_case.case_no,nonwarranty_diagnosis.date,status.name,customer.customer_name,customer.mobile")
			->from('nonwarranty_diagnosis','customer','users','status','nonwarranty_case')
			->join('customer','customer.service_id=nonwarranty_diagnosis.service_id')
			->join('users','users.id=nonwarranty_diagnosis.engineer_id')
			->join('status','nonwarranty_diagnosis.status_id=status.id')
			->join('nonwarranty_case','nonwarranty_case.service_id=nonwarranty_diagnosis.service_id')
			->where('nonwarranty_case.status_id != 21')
			->where('users.id',$id)
			->where('nonwarranty_diagnosis.status_id',1)
		    ->add_column("Actions",
			"<center>		
								<a href='index.php/engineer/diagnosis/view_detail/$1'>
								<i class='icon-edit'title='View Detail'></i>
								</a>
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}

public function edit_case($id)
	{
	$query = $this->db->get_where('customer', array('id' => $id));
		return $query;
	}
	public function edit_access($id)
	{
	$query = $this->db->get_where('customer_accesories', array('customer_id' => $id));
		return $query;
	}
	public function get_countrys()
	{
	$query= $this->db->get('country');
	return $query;
	}
	public function get_case_no($id)
	{
	$query = $this->db->get_where('case', array('id' => $id));
	return $query;
	
	}
	public function get_case_nonwarranty($id)
	{
	$query = $this->db->get_where('nonwarranty_case', array('id' => $id));
	return $query;
	
	}
    public function update_diagnosis($edit_id,$insert){
		$this->db->update('diagnosis',$insert,array('service_id'=>$edit_id));
	
	
	}
	 public function update_nonwarranty_diagnosis($edit_id,$insert){
		$this->db->update('nonwarranty_diagnosis',$insert,array('service_id'=>$edit_id));
	}
	public function update_case($case,$id)
	{
	
	$this->db->update('case',$case,array('service_id'=>$id,'status_id'=>1,));
	
	}
	public function update_nonwarranty_case($case,$id)
	{
	
	$this->db->update('nonwarranty_case',$case,array('service_id'=>$id));
	
	}
	public function update_case1($id,$hp)
	{
	$case=array('status_id'=>3,'hp_case' =>$hp,);
	$this->db->update('case',$case,array('id'=>$id));
	
	}
	public function update_nonwarranty_case1($id)
	{
	$case=array('status_id'=>3,);
	$this->db->update('nonwarranty_case',$case,array('id'=>$id));
	
	}
public function get_current_view($id)
	{
	$this->datatables
			->select("customer.id as id, case.case_no,case.date,status.name,customer.customer_name,customer.mobile")
			->from('diagnosis','customer','users','status','case')
			->join('customer','customer.service_id=diagnosis.service_id')
			->join('users','users.id=diagnosis.enginer_id')
			->join('status','diagnosis.status_id=status.id')
			->join('case','diagnosis.case_id=case.id')
			->where('users.id',$id)
			->where('diagnosis.status_id',2)
		    ->add_column("Actions",
			"<center>		
								<a href='index.php/engineer/diagnosis/dispatch_detail/$1'>
								<i class='icon-edit '></i>
								</a>
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}
	public function nonwarranty_current_view($id)
	{
	$this->datatables
			->select("customer.id as id, nonwarranty_case.case_no,nonwarranty_case.date,status.name,customer.customer_name,customer.mobile")
			->from('nonwarranty_diagnosis','customer','users','status')
			->join('customer','customer.service_id=nonwarranty_diagnosis.service_id')
			->join('users','users.id=nonwarranty_diagnosis.engineer_id')
			->join('status','nonwarranty_diagnosis.status_id=status.id')
			->join('nonwarranty_case','nonwarranty_diagnosis.service_id=nonwarranty_case.service_id')
			->where('users.id',$id)
			->where('nonwarranty_diagnosis.status_id',2)
			->where('nonwarranty_case.status_id != 21')
		    ->add_column("Actions",
			"<center>		
								<a href='index.php/engineer/diagnosis/nonwarranty_dispatch_detail/$1'>
								<i class='icon-edit '></i>
								</a>
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}
	

public function get_case($id)
{
$this->db->select('case.case_no,case.id');
	$this->db->from('case', 'customer' );
	$this->db->join('customer', 'case.service_id= customer.service_id ');
	$this->db->where('customer.id',$id);
	$this->db->where('case.status_id != 22');
	$q = $this->db->get();
	return $q;
		
	
}
public function get_nonwarrantycase($id)
{
$this->db->select('nonwarranty_case.case_no,nonwarranty_case.id');
	$this->db->from('nonwarranty_case', 'customer' );
	$this->db->join('customer', 'nonwarranty_case.service_id= customer.service_id  '  );
	$this->db->where('customer.id',$id);
	$q = $this->db->get();
	return $q;
		
	
}
public function get_diagnosis($id)
{
$this->db->select('diagnosis.id');
	$this->db->from('diagnosis', 'case' );
	$this->db->join('case', 'diagnosis.service_id= case.service_id  '  );
	$this->db->where('case.id',$id);
	$q = $this->db->get();
	return $q;	
}
public function nonwarranty_diagnosis($id)
{
$this->db->select('nonwarranty_diagnosis.id');
	$this->db->from('nonwarranty_diagnosis', 'nonwarranty_case' );
	$this->db->join('nonwarranty_case', 'nonwarranty_diagnosis.service_id= nonwarranty_case.service_id  '  );
	$this->db->where('nonwarranty_case.id',$id);
	$q = $this->db->get();
	return $q;	
}
public function update_status($id)

{ 
$insert=array('status_id'=>3,'completion_date'=>date('Y-m-d'),);
		$this->db->update('diagnosis',$insert,array('id'=>$id));
	}
public function update_nonwarranty_status($id)

{ 
$insert=array('status_id'=>3,'completion_date'=>date('Y-m-d'),);
$this->db->update('nonwarranty_diagnosis',$insert,array('id'=>$id));
}
function dispatch_diagnosis($data)
{
$this->db->insert('so',$data);
	}
function dispatch_nonwarranty_diagnosis($data)
{
$this->db->insert('nonwarranty_part',$data);
	}

public function get_dispatch_view($id)
	{
	$this->datatables
			->select("case.id as id, case.case_no,case.hp_case,case.date,status.name,customer.customer_name,customer.mobile")
			->from('diagnosis','customer','users','status')
			->join('customer','customer.service_id=diagnosis.service_id')
			->join('users','users.id=diagnosis.enginer_id')
			->join('status','diagnosis.status_id=status.id')
			->join('case','diagnosis.case_id=case.id')
			->where('users.id',$id)
			->where('diagnosis.status_id',3)
		    ->add_column("Actions",
			"<center>		
								<a href='index.php/engineer/diagnosis/dispatch_detail_view/$1'>
								<i class='icon-edit '></i>
								</a>
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}
	public function nonwarranty_dispatch_view($id)
	{
	$this->datatables
			->select("nonwarranty_case.id as id, nonwarranty_case.case_no,nonwarranty_case.date,status.name,customer.customer_name,customer.mobile")
			->from('nonwarranty_diagnosis','customer','users','status','nonwarranty_case')
			->join('customer','customer.service_id=nonwarranty_diagnosis.service_id')
			->join('users','users.id=nonwarranty_diagnosis.engineer_id')
			->join('status','nonwarranty_diagnosis.status_id=status.id')
			->join('nonwarranty_case','nonwarranty_diagnosis.service_id=nonwarranty_case.service_id')
			->where('users.id',$id)
			->where('nonwarranty_diagnosis.status_id',3)
			->where('nonwarranty_case.status_id != 21')
		    ->add_column("Actions",
			"<center>		
								<a href='index.php/engineer/diagnosis/dispatch_detail_nonwarranty/$1'>
								<i class='icon-edit '></i>
								</a>
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}
public function get_slo($id)
{
$query = $this->db->get_where('so', array('case_id' => $id));
	 return $query->result();
}
public function get_part($id)
{
$query = $this->db->get_where('nonwarranty_part', array('case_id' => $id));
	 return $query->result();
}
public function chk_serviceid($id)
{
$query = $this->db->get_where('nonwarranty_case', array('service_id' => $id));
return $query;

}
	
	}